﻿//
// Created by Administrator on 2025/7/8.
//
#include <iostream>
#include <thread>
#include <mutex>

std::once_flag flag;

void init() {
    std::cout << "Initialized once." << std::endl;
}

void worker() {
    std::call_once(flag, init);  // 保证只调用一次
}

int main() {
    std::thread t1(worker);
    std::thread t2(worker);
    t1.join();
    t2.join();
    return 0;
}
